package com.yx.china.project.api;

import com.yx.china.project.entities.Payment;
import com.yx.china.project.entities.ResponseResult;
import com.yx.china.project.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
public class PayApi {
    @Resource
    private PayService payService;
    @Value("${server.port}")
    private String port;
    @PostMapping(value = "/payment/create")
    public ResponseResult create(@RequestBody Payment payment){
        int result = payService.createPay(payment);
        log.info("*****插入结果："+result);
        if(result > 0){
            return new ResponseResult(200,"插入数据成功:"+port);
        }else{
            return new ResponseResult(444,"插入数据失败",null);
        }
    }
    @GetMapping(value = "/payment/getZk/{id}")
    public ResponseResult<Payment> getPaymentById(@PathVariable("id") Long id){
        Payment payment = payService.getPaymentById(id);
        log.info("*****查询结果："+payment);
        if(payment != null){
            return new ResponseResult(200,"查询成功:"+port,payment);
        }else{
            return new ResponseResult(444,"没有对应记录,查询ID："+id,null);
        }
    }
}
